package nioTest.com.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author      : yang.xp
 * @date        : 2022/3/14 0014 20:25
 * @description : 完成文件的copy
 */
public class NIOFileChannel04 {

    public static void main(String[] args) {
        try {
            FileInputStream fileInputStream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\Screenshot.jpg");
            FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\Screenshot2.jpg");

            FileChannel fileInputStreamChannel = fileInputStream.getChannel();
            FileChannel fileOutputStreamChannel = fileOutputStream.getChannel();

            fileOutputStreamChannel.transferFrom(fileInputStreamChannel, 0, fileInputStreamChannel.size());

            fileInputStreamChannel.close();
            fileOutputStreamChannel.close();

            fileInputStream.close();
            fileOutputStream.close();


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }
}
